#ifndef IPROPERTY_OBJECT_H
#define IPROPERTY_OBJECT_H

#include <QtCore/QVariant>
#include <QtGui/QStyledItemDelegate>

namespace core
{

class IVetoObject
{
public:
    virtual bool valueChanged(const QString& propertyName,
        const QString& propertyText, const QVariant& oldValue,
        const QVariant& newValue, QString& reason) const = 0;
};

class Property
{
public:
    Property(bool isVisible = true) :
        Name(), Text(), IsNullable(false), m_isVisible(isVisible), m_veto(0),
        m_value(), m_delegate(0)
    {
    }

    bool operator==(const Property& other)const
    {
        bool ret = Name == other.Name;

        return ret;
    }

    QString setValue(const QVariant& value)
    {
        QString ret;

        bool acceptChange = m_veto == 0 ? true :
            m_veto->valueChanged(Name, Text, m_value, value, ret);

        if (acceptChange)
        {
            m_value = value;
        }

        return ret;
    }

    void setVetoObject(IVetoObject* object)
    {
        m_veto = object;
    }

    void setDelegate(QStyledItemDelegate* delegate)
    {
        m_delegate = delegate;
    }

    QStyledItemDelegate* delegate() const
    {
        return m_delegate;
    }

    QVariant value() const
    {
        return m_value;
    }

    bool isVisibleToEditor() const
    {
        return m_isVisible;
    }

    void setVisibleToEditor(bool visible)
    {
        m_isVisible = visible;
    }

public:
    QString Name;
    QString Text;
    bool IsNullable;

private:
    bool m_isVisible;
    IVetoObject* m_veto;
    QVariant m_value;
    QStyledItemDelegate* m_delegate;
};

class IPropertyObject
{
public:
    virtual QList<Property> properties() const = 0;

    virtual QVariant propertyValue(const QString& propertyName) const = 0;

    virtual void propertyChanged(const QString& property,
        const QVariant& newValue, bool silent = false) = 0;

    virtual QVariantList optionList(const QString& propertyName) const = 0;
    virtual QVariantList autocomplete(const QString& propertyName) const = 0;

    virtual QString name() const = 0;
};

} // namespace core

#endif
